package my.mall.common.util

import my.mall.common.enums.RespMetaEnum
import my.mall.common.pojo.CommonResp
import my.mall.common.pojo.PageInfo
import my.mall.common.pojo.PageResp

object RespUtils {

    fun success(): CommonResp<*> {
        return success<Any?>(null)
    }

    fun <T> success(data: T): CommonResp<T> {
        return CommonResp(RespMetaEnum.SUCCESS.status, RespMetaEnum.SUCCESS.msg, data)
    }

    fun <T> success(pageNum: Long, pageSize: Long, data: List<T>): CommonResp<PageResp<T>> {
        return CommonResp(RespMetaEnum.SUCCESS.status, RespMetaEnum.SUCCESS.msg, PageResp(data, PageInfo(pageNum, pageSize)))
    }

    fun <T> success(pageNum: Long, pageSize: Long, totalRecord: Long, data: List<T>): CommonResp<PageResp<T>> {
        val pageInfo = PageInfo(pageNum, pageSize)
        pageInfo.totalRecord = totalRecord
        val pageResp = PageResp(data, pageInfo)
        return CommonResp(RespMetaEnum.SUCCESS.status, RespMetaEnum.SUCCESS.msg, pageResp)
    }

    fun <T> success(msg: String, data: T): CommonResp<T> {
        return CommonResp(RespMetaEnum.SUCCESS.status, msg, data)
    }

    fun <T> warning(meta: RespMetaEnum): CommonResp<T?> {
        return CommonResp(meta.status, meta.msg, null)
    }

    fun warning(status: Int, msg: String): CommonResp<*> {
        return CommonResp<Any?>(status, msg, null)
    }
}
